home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / EPASM13.ARJ / SAMPLE.ASM < prev   
Assembly Source File  |  1990-10-14  |  7KB  |  207 lines

  1. ;
  2. ;        Channel Microcontroller Program
  3. ;        7/29/87        Joseph Hora
  4. ;
  5. ;
  6. ;       This program is a test version of a program to read data from 
  7. ;    counters and to output the sums to a main microcontroller that
  8. ;    controls several devices running this program.
  9. ;
  10. ;    This is the "slave" program, and the program for the
  11. ;    main microcontroller is the "master" program, not shown in this
  12. ;    sample.
  13. ;
  14. ;
  15. ;    Register assignments:  register Bank 0
  16. ;
  17. ;    R0 - Work register
  18. ;    R1 - Base Address of Bank to be used for current pass
  19. ;    R2 - Previous base address used
  20. ;    R3 - Previous PORT 1 reading
  21. ;    R4 - Previous PORT 2 reading
  22. ;    R5 - Current PORT 1 reading
  23. ;    R6 - Current PORT 2 reading
  24. ;    R7 - Work register
  25. ;
  26. ;
  27. ;
  28. ;        Constants    ;These numbers are in Hexidecimal
  29. CONST    BankA    20              ;Bank A: 32-63 (decimal)
  30. CONST    BankB    40        ;Bank B: 64-95     "
  31. CONST    BankC    60        ;Bank C: 96-127    "
  32. ;
  33. ;        Main Routine
  34.     ORG    00        ;Program starts here in memory
  35. Begin    Call    Reset        ;initialize parameters
  36.     Jmp    Output        ;
  37. Main    JT0    Stat1        ;If T0 set, goto Stat1
  38.     JT1    Stat2        ;If not T0 and T1, go here
  39.     Mov    R1,#BankA    ;Neither T0 or T1, so Bank A<<<<
  40.     Jmp    StatEnd        ;Exit Stat section
  41. Stat1    JNT1    Stat3        ;
  42.     Mov    R1,#00        ;If T1 also set, then WAIT mode<<<
  43.     Jmp    Main
  44. Stat3    Mov    R1,#BankB    ;T0 and not T1, so Bank B<<<<
  45.     Jmp    StatEnd        ;
  46. Stat2    Mov    R1,#BankC    ;not T0 and T1, so Bank C<<<<
  47. StatEnd    Mov    A,R1        ;Get current base address
  48.     XRL    A,R2        ;Compare to base address last time
  49.     JZ    TakDat        ;If same, go increment counters
  50.     MOV    A,R1        ;Different bank this time, must reset
  51.     MOV    R2,A        ;set "old" base address here
  52.     IN    A,P1        ;set old port reading equal
  53.     MOV    R3,A        ;     to current one
  54.     IN    A,P2        ;same for port 2
  55.     MOV    R4,A
  56.     JMP    Main        ;End of Main Program loop
  57. ;
  58. ;
  59. ;        Reset Routine
  60. Reset    EN    I        ;Enable interrupt
  61.     MOV    R1,#00        ;This will signal wait mode in the main prog
  62.     MOV    R0,#BankA    ;First address to be zeroed
  63.     MOV    R7,#20        ;32 decimal (16 channels *2 bytes)
  64.     MOV    A,#00        ;Zero A
  65. Loop    MOV    @R0,A        ;Zero memory at location given by R0
  66.     INC    R0        ;advance to next location
  67.     MOV    @R0,A        ;Zero next
  68.     INC    R0        ;
  69.     MOV    @R0,A        ;Zero Next (3 for 3 banks)
  70.     INC    R0
  71.     DJNZ    R7,#Loop    ;Loop again if not done
  72.     MOV    R2,A        ;Set previous base to zero to initialize
  73.     JMP    Main        ;Return to main program
  74. ;
  75. ;
  76. ;        Data Output to Main Microcontroller
  77. ;
  78. ;    Data output to the main MC is controlled by the INT (interrupt) line.
  79. ;    When the INT is triggered while in the data taking routine, this
  80. ;    routine is called.  The interrupt line is disabled, meaning it can be
  81. ;    used as a testable signal pin.  After the interrupt is reset, the 
  82. ;    routine gets the first data to be transferred, places it on the BUS,
  83. ;    and waits for another interrupt.  This second interrupt is to signal
  84. ;    that the data is being read by the main MC.  When the MC is done
  85. ;    reading the data, it will reset the interrupt.  Then this routine will
  86. ;    stop waiting and place the next byte of data on the BUS.
  87. ;         This process will continue until the MC has read all the data it
  88. ;    requires (either 1, 2, or 3 banks).  Then the MC will go on to other 
  89. ;    tasks, and this channel MC will wait in this routine until it receives
  90. ;    a RESET signal from the main MC.
  91. ;
  92. Output    DIS    I        ;Disable interrupt
  93. Wait    JNI    Start        ;Wait here until interrupt is reset
  94.     JMP     Wait        ;
  95. Start    MOV    R0,#BankA    ;Set to beginning of data area
  96. NxtDat    MOV    A,@R0        ;Get Data, put in A
  97.     OUTL    Bus,A        ;Put data on bus for main MC to read
  98. Wait1    JNI    Wait1        ;Wait for another interrupt 
  99. Wait2    JNI    Contin        ;Wait until interrupt is false
  100.     JMP    Wait2        ; before going on
  101. Contin    INC     R0        ;Proceed to next memory location
  102.     JMP    NxtDat        ;Output to MC
  103. ;
  104. ;
  105. ;        Reading channels and updating counters
  106. ;
  107. ;
  108. ;
  109. TakDat    MOV     A,R1        ;
  110.     MOV    R0,A        ;Move base address into pointer
  111.     IN     A,P2        ;Read port 2
  112.     MOV    R6,A        ;Store in register 6
  113.     IN    A,P1        ;Read port 1
  114.     MOV    R5,A        ;Store in R5
  115.     XRL    A,R3        ;Compare with previous reading
  116.     MOV    R7,A        ;Store comparison
  117.     MOV    R3,#1        ;Put a "1" in R3 (old PORT 1 not needed now)
  118.     CPL    A        ;not A
  119.     CALL    Update        ;Increment all counters 0-7
  120.     MOV    A,R6        ;Get current port 2
  121.     XRL    A,R4        ;Compare with old #2
  122.     MOV    R7,A        ;Store comparison
  123.     CPL    A        ;not A
  124.     Call    Update        ;Increment counters 8-15
  125.     MOV    A,R5        ;Get reading
  126.     MOV    R3,A        ;Store in "old" position
  127.     MOV    A,R6        ;get reading
  128.     MOV    R4,A        ;Store in "old" position
  129.     JMP     Main        ;go back to main program
  130. ;
  131. ;
  132. ;        Update Subroutine
  133. ;
  134. Update    CLR    C        ;get ready for addition
  135.     JB0    Clear0        ;If not changed, do not add 1
  136.     Mov    A,@R0        ;Get current counter value
  137.     Add    A,R3        ;Increment by 1
  138.     Mov    @R0,A        ;Store result
  139. Clear0    Inc    R0        ;Move to next address in counter
  140.     JNC    Bit1        ;If carry not set, no need to update
  141.     Inc    @R0        ;Increment data location by one
  142. Bit1    Inc    R0        ;Move to bit 1 counter
  143.     CLR    C        ;clear carry
  144.     JB1    Clear1        ;If not changed, do not add 
  145.     Mov    A,@R0        ;Get current value
  146.     Add    A,R3        ;Add 1
  147.     Mov    @R0,A        ;Store result
  148. Clear1    Inc    R0        ;next location in counter
  149.     JNC    Bit2        ;leave if carry not set
  150.     Inc    @R0        ;Carry set, so increment high order byte
  151. Bit2    Inc    R0        ;Move to bit 2 counter
  152.     CLR    C        ;clear carry
  153.     JB2    Clear2        ;If not changed, do not add 
  154.     Mov    A,@R0        ;Get current value
  155.     Add    A,R3        ;Add 1
  156.     Mov    @R0,A        ;Store result
  157. Clear2    Inc    R0        ;next location in counter
  158.     JNC    Bit3        ;leave if carry not set
  159.     Inc    @R0        ;Carry set, so increment high order byte
  160. Bit3    Inc    R0        ;Move to bit 3 counter
  161.     CLR    C        ;clear carry
  162.     JB3    Clear3        ;If not changed, do not add 
  163.     Mov    A,@R0        ;Get current value
  164.     Add    A,R3        ;Add 1
  165.     Mov    @R0,A        ;Store result
  166. Clear3    Inc    R0        ;next location in counter
  167.     JNC    Bit4        ;leave if carry not set
  168.     Inc    @R0        ;Carry set, so increment high order byte
  169. Bit4    Inc    R0        ;Move to bit 4 counter
  170.     CLR    C        ;clear carry
  171.     JB4    Clear4        ;If not changed, do not add 
  172.     Mov    A,@R0        ;Get current value
  173.     Add    A,R3        ;Add 1
  174.     Mov    @R0,A        ;Store result
  175. Clear4    Inc    R0        ;next location in counter
  176.     JNC    Bit5        ;leave if carry not set
  177.     Inc    @R0        ;Carry set, so increment high order byte
  178. Bit5    Inc    R0        ;Move to bit 5 counter
  179.     CLR    C        ;clear carry
  180.     JB5    Clear5        ;If not changed, do not add 
  181.     Mov    A,@R0        ;Get current value
  182.     Add    A,R3        ;Add 1
  183.     Mov    @R0,A        ;Store result
  184. Clear5    Inc    R0          ;next location in counter
  185.     JNC    Bit6        ;leave if carry not set
  186.     Inc    @R0        ;Carry set, so increment high order byte
  187. Bit6    Inc    R0        ;Move to bit 6 counter
  188.     CLR    C        ;clear carry
  189.     JB6    Clear6        ;If not changed, do not add 
  190.     Mov    A,@R0        ;Get current value
  191.     Add    A,R3        ;Add 1
  192.     Mov    @R0,A        ;Store result
  193. Clear6    Inc    R0        ;next location in counter
  194.     JNC    Bit7        ;leave if carry not set
  195.     Inc    @R0        ;Carry set, so increment high order byte
  196. Bit7    Inc    R0        ;Move to bit 7 counter
  197.     CLR    C        ;clear carry
  198.     JB7    Clear7        ;If not changed, do not add 
  199.     Mov    A,@R0        ;Get current value
  200.     Add    A,R3        ;Add 1
  201.     Mov    @R0,A        ;Store result
  202. Clear7    Inc    R0        ;next location in counter
  203.     JNC    EndBit        ;leave if carry not set
  204.     Inc    @R0        ;Carry set, so increment high order byte
  205. EndBit    Inc    R0        ;Proceed to next counter (in next bank)
  206.     Ret            ;Return to TakeDat
  207.